package com.hangxin.commons.util;

import java.util.List;

/**
 * 封装分页信息
 * 
 */
public class PageModel<T>
{

	public PageModel()
	{

	}



	public PageModel(int pageNo)
	{
		this.pageNo = pageNo < 1 ? 1 : (pageNo > this.pages ? this.pages : pageNo);
	}



	public PageModel(int pageNo, int pages)
	{
		this.pages = pages;
		this.pageNo = pageNo < 1 ? 1 : (pageNo > this.pages ? this.pages : pageNo);
	}



	public PageModel(int pageNo, int pages, int pageSize)
	{
		this.pages = pages;
		this.pageNo = pageNo < 1 ? 1 : (pageNo > this.pages ? this.pages : pageNo);
		this.pageSize = pageSize;
	}



	public PageModel(int pageNo, int totalRecords, List<T> list, int pageSize)
	{
		this.totalRecords = totalRecords;
		this.list = list;
		this.pageSize = pageSize;
		this.pages = (this.totalRecords + this.pageSize - 1) / this.pageSize;
		this.pageNo = pageNo < 1 ? 1 : (pageNo > this.pages ? this.pages : pageNo);
	}

	// 结果�?
	private List<T> list;

	// 查询记录�?
	/**
	 * 查询记录总数
	 */
	private int totalRecords;

	// 每页多少条数�?

	/**
	 * 每页有多少条数据
	 */
	private int pageSize = 16;

	// 第几�?
	/**
	 * 当前是第几页
	 */
	private int pageNo = 1; 

	// 总页�?
	/**
	 * 总页数
	 */
	private int pages = 1;



	public List<T> getList()
	{
		return list;
	}



	public void setList(List<T> list)
	{
		this.list = list;
	}



	/**
	 * 查询记录总数
	 */
	public int getTotalRecords()
	{
		return totalRecords;
	}



	/**
	 * 查询记录总数
	 */
	public void setTotalRecords(int totalRecords)
	{
		this.totalRecords = totalRecords;
	}



	/**
	 * 每页有多少条数据
	 */
	public int getPageSize()
	{
		return pageSize;
	}



	/**
	 * 每页有多少条数据
	 */
	public void setPageSize(int pageSize)
	{
		this.pageSize = pageSize;
	}



	/**
	 * 当前是第几页
	 */
	public int getPageNo()
	{
		return pageNo;
	}



	/**
	 * 当前是第几页
	 */
	public void setPageNo(int pageNo)
	{
		if(pages!=0){
			this.pageNo = (pageNo < 1 )? 1 : ((pageNo > this.pages) ? this.pages : pageNo);
		}else{
			this.pageNo = (pageNo < 1 )? 1 :pageNo;
		}
		
	}



	/**
	 * 总页数
	 */
	public int getPages()
	{
		return pages;
	}



	/**
	 * 总页数
	 */
	public void setPages(int pages)
	{
		this.pages = pages;
	}



	/**
	 * 总页数
	 */
	public void setPages()
	{
		this.pages = (this.totalRecords + this.pageSize - 1) / this.pageSize;
	}

}
